package com.xy.modular.basics.service.impl;

import com.xy.framework.base.dao.IBaseDao;
import com.xy.framework.base.service.BaseServiceImpl;
import com.xy.framework.exceptions.ValidateParamException;
import com.xy.framework.pager.PageRequest;
import com.xy.modular.basics.dao.UserAuthLocalMapper;
import com.xy.modular.basics.dao.UserMapper;
import com.xy.modular.basics.entity.user.User;
import com.xy.modular.basics.entity.user.UserAuthLocal;
import com.xy.modular.basics.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class IUserServiceImpl extends BaseServiceImpl<User, java.lang.String> implements IUserService {

	@Resource
	private UserMapper userMapper;

	@Resource
	private UserAuthLocalMapper userAuthLocalMapper;

	@SuppressWarnings("rawtypes")
	@Override
	protected IBaseDao getBaseDao() {
		return this.userMapper;
	}

	@Override
	public User login(UserAuthLocal userAuthLocal) {
		UserAuthLocal uA = userAuthLocalMapper.getByIC(userAuthLocal);
		if (uA != null) {
			return userMapper.getById(uA.getAuthId());
		}
		return null;
	}

	@Override
	public Boolean validateEntity(UserAuthLocal userAuthLocal) {
		return true;
	}

	@Override
	public void validateEntity(User user) throws ValidateParamException {
		// TODO Auto-generated method stub

	}

	@Override
	public void save(User user, UserAuthLocal userAuthLocal) {
		userMapper.save(user);
		userAuthLocal.setAuthId(user.getId());
		userAuthLocal.setPassword("2c7299d0cbcb15ad7356d26bb4458a5e");
		userAuthLocal.setSalt("GOFC4NDV");
		userAuthLocalMapper.save(userAuthLocal);
	}

	@Override
	public void update(User user, UserAuthLocal userAuthLocal) {
		userMapper.update(user);
		userAuthLocal.setAuthId(user.getId());
		userAuthLocalMapper.update(userAuthLocal);
	}
	
	private void findAllList(PageRequest pageRequest) {
		//return userMapper.findAllList(pageRequest);
	}

}
